/*
 * Copyright 2022-2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.aurora.generator.test.service.impl;

import lombok.RequiredArgsConstructor;
import org.aurora.generator.core.UidGenerator;
import org.aurora.generator.test.entity.SnowflakeIdEntity;
import org.aurora.generator.test.service.SnowflakeIdService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.invoke.MethodHandles;

/**
 * snowflake id
 *
 * @author Evan Zhai
 * @since 1.0.0
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SnowflakeIdServiceImpl implements SnowflakeIdService {

	private final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

	final UidGenerator uidGenerator;

	@Override
	public SnowflakeIdEntity getId() {
		long snowflakeId = uidGenerator.getUID();
		LOGGER.info("generator snowflake id is {}", snowflakeId);
		return SnowflakeIdEntity.builder().id(snowflakeId).build();
	}

}
